﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Acme.Common.DataGeneration;
using Acme.Common.Infrastructure;
using Acme.MVVM.Scenarios.Infrastructure;
using Acme.MVVM.Scenarios.Model;

namespace Acme.MVVM.Scenarios.Views
{
    public class ListBoxItemExecuteCommandViewModel : ScenarioViewModelBase
    {

        ObservableCollection<Person> _people;
        ICommand _viewPersonCommand;
        Person _selectedPerson;

        public Person SelectedPerson
        {
            get { return _selectedPerson; }
            set
            {
                _selectedPerson = value;
                RaisePropertyChanged("SelectedPerson");
            }
        }

        public ICommand ViewPersonCommand
        {
            get { return _viewPersonCommand ?? (_viewPersonCommand = new RelayCommand<Person>(p => this.SelectedPerson = p)); }
        }

        public ObservableCollection<Person> People
        {
            get { return _people; }
            private set
            {
                _people = value;
                RaisePropertyChanged("People");
            }
        }

        public override string TabHeaderText
        {
            get { return "ListBoxItem Executing Command"; }
        }

        public ListBoxItemExecuteCommandViewModel()
        {
            var data = new DataGenerator();
            data.SeedSequentialInteger(1000, 1);
            var list = new List<Person>();
            for (Int32 i = 0; i < 10; i++)
            {
                list.Add(new Person { Id = data.GetSequentialInteger(), FirstName = data.GetFirstName(), LastName = data.GetLastName() });
            }
            list.Sort();
            this.People = new ObservableCollection<Person>(list);
        }
    }
}
